import wx

from Estabelecimento import Estabelecimento
from Repositorio import Armazenar
from Arvore import Arvore

class PanelCadastrarE(wx.Panel):
    def _init_ctrls(self, prnt):

        wx.Panel.__init__(self, id=-1, name='', parent=prnt, size=wx.Size(411, 213),
              style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(420, 320))

        self.parent = prnt

        self.labelCadastrarEstab = wx.StaticText(id=-1,
              label='Cadastrar Estabelecimento', name='staticText1', parent=self,
              pos=wx.Point(115, 2), size=wx.Size(107, 23), style=0)
        self.labelCadastrarEstab.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, 'Tahoma'))

        self.labelNome = wx.StaticText(id=-1, label='Nome: ',
              name='staticText1', parent=self, pos=wx.Point(40, 60),
              size=wx.Size(42, 14), style=0)
        self.labelNome.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              'Tahoma'))

        self.labelCnpj = wx.StaticText(id=-1, label='CNPJ: ', name='staticText1',
              parent=self, pos=wx.Point(40, 38), size=wx.Size(42, 14), style=0)
        self.labelCnpj.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              'Tahoma'))

        self.labelEndereco = wx.StaticText(id=-1, label='Endereco: ', name='staticText1',
              parent=self, pos=wx.Point(40, 82), size=wx.Size(42, 14), style=0)
        self.labelEndereco.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              'Tahoma'))

        self.labelInicio = wx.StaticText(id=-1, label='Inicio:(hh:mm)',
              name='staticText1', parent=self, pos=wx.Point(40, 104),
              size=wx.Size(43, 14), style=0)
        self.labelInicio.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              'Tahoma'))


        self.labelFim = wx.StaticText(id=-1, label='Fim:(hh:mm)',
              name='staticText1', parent=self, pos=wx.Point(40, 126),
              size=wx.Size(43, 14), style=0)
        self.labelFim.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              'Tahoma'))

        
        self.textInicio = wx.TextCtrl(id=-1, name='textCtrl1', parent=self,
              pos=wx.Point(140, 104), size=wx.Size(192, 21), style=0)

        self.textFim = wx.TextCtrl(id=-1, name='textCtrl1', parent=self,
              pos=wx.Point(140, 126), size=wx.Size(192, 21), style=0)


        self.textNome = wx.TextCtrl(id=-1, name='textCtrl1', parent=self,
              pos=wx.Point(140, 60), size=wx.Size(192, 21), style=0)

        self.textCnpj = wx.TextCtrl(id=-1, name='textCtrl1', parent=self,
              pos=wx.Point(140, 38), size=wx.Size(192, 21), style=0)

        self.textEndereco = wx.TextCtrl(id=-1, name='textCtrl1', parent=self,
              pos=wx.Point(140, 82), size=wx.Size(192, 21), style=0)

        self.botaoCadastrar = wx.Button(id=11, label='Cadastrar',
              name='button1', parent=self, pos=wx.Point(240, 156),
              size=wx.Size(75, 23), style=0)

        

        self.Bind(wx.EVT_BUTTON, self.cadastrar, id=11)


    def cadastrar(self, event):
        rep= Armazenar()
        horario=[]
        cnpj = self.textCnpj.GetValue()
        nome = self.textNome.GetValue()
        endereco = self.textEndereco.GetValue()        
        inicio =  self.textInicio.GetValue()
        fim =  self.textFim.GetValue()
        horario.append(inicio)
        horario.append(fim)
        p = Estabelecimento(nome, cnpj, endereco, horario)
        
        arvore = rep.getArvoreE()
        rep.apagar('estabelecimento')
        arvore.insertNodeUnique(p)#ADICIONA O OBJETO ACIMA NA ARVORE ACIMA
        arvore.armazenarEmOrdemE(arvore.rootNode)#CADASTRA TODOS OS NODOS DA ARVORE
        mensagem = wx.MessageDialog(None, 'Cadastro realizado com sucesso !!!', ':: BSI Card ::',style = wx.OK)
        msg = mensagem.ShowModal()
        



    def __init__(self, parent):

        

        self._init_ctrls(parent)
        self.AcceptsFocus()
        self.Enable(True) 
